package io.renren.system;


import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {
    /**
     * 使用EasyPoi模板导出数据
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception{
        TemplateExportParams params = new TemplateExportParams(
                "template/Test.xlsx",0);
        Map<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < 4; i++) {
            Map<String, Object> testMap = new HashMap<String, Object>();
            testMap.put("index", i);
            testMap.put("name", "小明"+i);
            testMap.put("age", "年龄"+i);
            testMap.put("dept", "部门"+i);
            mapList.add(testMap);
        }
        map.put("maplist", mapList);
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        File savefile = new File("D:/");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream("D:/Test-data.xlsx");
        workbook.write(fos);
        fos.close();
    }
}
